﻿namespace TrixPlugin.Common
{
	internal class StrategyControlVM : Plugins.Base.Common.StrategyControlVMBase
	{
		#region Properties

		public new StrategyControlData Data
		{
			get
			{
				return (StrategyControlData)base.Data;
			}
		}

		public int TrixPeriod
		{
			get
			{
				return this.Data.TrixPeriod;
			}
			set
			{
				this.Data.TrixPeriod = value;
			}
		}

		public int BarPeriod
		{
			get
			{
				return this.Data.BarPeriod;
			}
			set
			{
				this.Data.BarPeriod = value;
			}
		}

		public int Volume
		{
			get
			{
				return this.Data.Volume;
			}
			set
			{
				this.Data.Volume = value;
			}
		}

		public decimal StopLoss
		{
			get
			{
				return this.Data.StopLoss;
			}
			set
			{
				this.Data.StopLoss = value;
			}
		}

		public bool Inverted
		{
			get
			{
				return this.Data.Inverted;
			}
			set
			{
				this.Data.Inverted = value;
			}
		}

		public OperationMode WorkingMode
		{
			get
			{
				return this.Data.WorkingMode;
			}
			set
			{
				this.Data.WorkingMode = value;
			}
		}
		
		#endregion

		#region Public Methods

		public StrategyControlVM() : base(new StrategyControlData())
		{
		}

		protected override string ValidateField(string fieldName)
		{
			string result = null;

			if (fieldName == "TrixPeriod")
			{
				if (this.TrixPeriod <= 0)
				{
					base.ValidatedErrors[fieldName] = true;
					result = "The min period has to be greater than 0";
				}
			}
			else if (fieldName == "BarPeriod")
			{
				if (this.BarPeriod <= 0)
				{
					base.ValidatedErrors[fieldName] = true;
					result = "The min period has to be greater than 0";
				}
			}
			else if (fieldName == "Volume")
			{
				if (this.Volume <= 0)
				{
					base.ValidatedErrors[fieldName] = true;
					result = "The volume has to be greater than 0";
				}
			}
			else if (fieldName == "StopLoss")
			{
				if (this.StopLoss < 0)
				{
					base.ValidatedErrors[fieldName] = true;
					result = "The stop loss has to be greater or equal to 0";
				}
			}

			return result;
		}

		#endregion
	}
}
